<template>
    <div class="collection__elements j-scrollElement" v-if="props.newsData.length > 0">
        <!-- 单个futures -->
        <div class="element element--article newswires DowJonesNewswires" v-for="(item, index) in props.newsData"
            :key='index'>
            <figure class="article__figure">
                <div class="figure__image disableShadowBox" @click="toPush(item)">
                    <img v-if="item.imgUrl == null" src="../../../assets/noimg.png" alt="">
                    <img :src='item.imgUrl' v-else>
                </div>
            </figure>
            <div class="article__content">
                <h3 class="article__headline">
                    <span class='article__label opinion' v-if='item.opinion'>{{ item.opinion }}</span>
                    <div class="link" @click="toPush(item)">{{ item.title
                        }}</div>
                </h3>

                <div class="content--secondary" v-if="!istime && item.company">
                    <div class="group group--tickers">
                        <bg-quote :class="[item.data < 0 ? 'negative' : 'positive']">
                            <router-link class="ticker" :to="{ name: 'stockDetail', params: { symbol: item.company } }">
                                <span class="ticker__symbol">{{ item.company }}</span>
                                <bg-quote :class="[item.data < 0 ? 'negative' : 'positive']">{{ item.ticketChange
                                    }}</bg-quote>
                                <i class="icon" v-if="item.data"></i>
                            </router-link>
                        </bg-quote>
                    </div>
                </div>
                <div class="article__details" v-else>
                    <span class="article__timestamp">{{ formateDate(item.createTime) }}<span v-if="item.author">by{{
                        item.author }}</span></span>
                </div>
                <div class="article__details">
                    <span class="article__timestamp">{{ item.content3 }}</span>

                    <span class="article__author">{{ item.content4 }}</span>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
const props = defineProps(['newsData', 'istime'])
import { formateDate } from '@/utils/timeHandle';
import { useRouter } from 'vue-router'
const router = useRouter()
if (props.newsData.length > 0) {
    props.newsData.forEach((item) => {
        if (item.ticketChange && item.ticketChange !== null) {
            item.data = parseFloat(item.ticketChange) / 100;
        }
    })
}
const toPush = (data) => {
    router.push({ name: 'NewDetail', params: { uuid: data.uuid, author: data.author } })
}
</script>
<style scoped lang='scss'></style>